//
//  ViewController.m
//  BluetoothPrint
//
//  Created by wang on 2017/11/3.
//  Copyright © 2017年 wang. All rights reserved.
//

#import "ViewController.h"
#import "WYHBLEPrinterTool.h"
#import "WYHMFIPrinterTool.h"
#import "PrintDataAppendTool.h"
#import "SelectPrinterViewController.h"
@interface ViewController ()<WYHBLEPrinterToolDelegate>

/**
 可以自己写个继承  设置固定打印参数
 */
@property (nonatomic, strong) PrintDataAppendTool *printDataTool;
@property (nonatomic, strong) WYHBLEPrinterTool *printerTool;
@property (nonatomic, strong) WYHMFIPrinterTool *printerMFITool;

@property (weak, nonatomic) IBOutlet UIButton *selectPrinter;
@property (weak, nonatomic) IBOutlet UISwitch *mfiSwitch;

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    
    NSArray *jsonArr = @[@"广州是广东省省会、",@"国家中心城市、",@"超大城市、",@"南部战区司令部驻地。",@"是国务院定位的国际大都市",@"、国际商贸中心、国际综合交通枢纽",@"、国家综合性门户城市、国家历史",@"文化名城[1-2]  。从秦朝开始，广州一直是华南地区",@"的政治、军事、经济、文化和",@"科教中心。广州从3世纪30年代起",@"成为海上丝绸之路的",@"主港，唐宋时期成为中国第一大港，明清两代成为中国唯一的对外",@"贸易大港[",@"3]  ",@"。",@"广州被全球最权威的世界城市研究机构GaWC评为世界一线城市；五",@"次被",@"福布斯评为中国大陆最佳商业城市第一位[4-5]  。广州总部经济发展能力居全国前三，在广州投资的外资企业达2.7万家；世界500强企业289家，其中120家把总部或地区",@"总部设在广州[6-8]  。广州互联网企业超过3000家，诞生了微信、唯品会",@"、YY语音、酷狗音乐、网易、UC浏览器等[9]  。2016年，",@"广州高新技术企业增量居全国第二，仅次于北京。2017年财富全球论坛将在广州举",@"办]"];
    [dic setObject:jsonArr forKey:@"json"];
    self.printDataTool = [PrintDataAppendTool new];
    self.printDataTool.printDic = dic;
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)printerErrorHint:(PrintErrorType)type
{
    NSLog(@"%ld",type);
}

/**
 打印成功
 */
- (void)printSuccess
{
   NSLog(@"打印成功");
}
- (IBAction)printButton:(id)sender {
    
    if (self.mfiSwitch.on) {
        self.printerMFITool = [WYHMFIPrinterTool new];
        self.printerMFITool.dataTool = self.printDataTool;
        [self.printerMFITool startToPrint];
    }else{
        self.printerTool = [WYHBLEPrinterTool new];
        self.printerTool.delegate = self;
        self.printerTool.dataTool = self.printDataTool;
        [self.printerTool startToPrint];

    }    
}

- (IBAction)cliickMFISwitch:(UISwitch *)sender {
    [self.selectPrinter setTitle:@"选择打印机" forState:UIControlStateNormal];
    self.printDataTool.printerParam.printerName = @"";
    self.printDataTool.printerParam.printerUUID = @"";
}

//选择打印机
- (IBAction)selectPrinter:(UIButton *)sender {
    
    SelectPrinterViewController *selectPrinterVC = [SelectPrinterViewController new];
    selectPrinterVC.MFI = self.mfiSwitch.on;
    selectPrinterVC.didSelect = ^(NSString *name, NSString *uuidStr) {
        [sender setTitle:name forState:UIControlStateNormal];
        self.printDataTool.printerParam.printerName = name;
        self.printDataTool.printerParam.printerUUID = uuidStr;
    };
    [self presentViewController:selectPrinterVC animated:YES completion:nil];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
